package me.jiatao.baselibrary.rx


import io.reactivex.Observable
import me.jiatao.baselibrary.common.ResultCode
import me.jiatao.baselibrary.data.protocol.HttpResult
import me.jiatao.baselibrary.exception.BaseException
import io.reactivex.functions.Function


/**
 *   通用数据类型转换封装
 */
class BaseFunc<T> : Function<HttpResult<T>, Observable<T>> {
    override fun apply(t: HttpResult<T>): Observable<T> {
        if (t.errorCode != ResultCode.SUCCESS) {
            return Observable.error(BaseException(t.errorCode, t.errorMsg))
        }

        return Observable.just(t.data)
    }
}
